import jwt from 'jsonwebtoken'
export default async function handler(req, res) {
    const token = req.cookies['token'];
    if(!token){
        res.status(200);
        res.json({
            code:-1,
            data:{},
            msg: "登录已过期，请重新登录"
        })
        return;
    }
    const payload = jwt.verify(token, process.env.JWT_SECRET)
    // console.log(100,payload);
    if(payload.account){
        //获取用户信息成功
        res.status(200);
        res.json({
            code:1,
            data:{
                nickname:payload.nickname,
                account:payload.account
            },
            msg: "获取成功"
        })
        return;
    }else{
        res.status(200);
        res.json({
            code:-1,
            data:{},
            msg: "登录已过期，请重新登录"
        })
        return;
    }
}